package com.woniu.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.mapper.ConfirmMapper;
import com.woniu.model.Confirm;
import com.woniu.service.ConfirmService;
import com.woniu.service.param.EmployConfirmParam;
import com.woniu.service.param.RefuseConfirmParam;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 吴彦祖
 * @since 2024年05月23日
 */
@Service
@Transactional
public class ConfirmServiceImpl extends ServiceImpl<ConfirmMapper, Confirm> implements ConfirmService {
    @Resource
    private ConfirmMapper confirmMapper;
    /**
     * 站点确认废品
     *
     * @param confirmId 确认表ID
     * @throws RuntimeException 如果废品确认表不存在
     */
    @Override
    public void locationConfirm(Integer confirmId) {
        Confirm confirm = confirmMapper.selectById(confirmId);
        if(confirm==null){
            throw new RuntimeException("不存在的废品确认表");
        }
        confirm.setStationConfirm(1);
        confirmMapper.updateById(confirm);
    }

    /**
     * 站点驳回废品确认
     *
     * @param form 拒绝确认参数
     * @throws RuntimeException 如果废品确认表不存在
     */
    @Override
    public void locationRefuseConfirm(RefuseConfirmParam form) {
        Confirm confirm = confirmMapper.selectById(form.getConfirmId());
        if(confirm==null){
            throw new RuntimeException("不存在的废品确认表");
        }
        confirm.setStationConfirm(2);
        confirm.setRefuseReason(form.getReason());
        confirmMapper.updateById(confirm);
    }

    /**
     * 员工驳回废品确认
     *
     * @param param 员工确认参数
     * @throws RuntimeException 如果废品确认表不存在
     */
    @Override
    public void employRefuseConfirm(EmployConfirmParam param) {
        Confirm confirm = confirmMapper.selectById(param.getConfirmId());
        if(confirm==null){
            throw new RuntimeException("不存在的废品确认表");
        }
        //等用户接口 根据用户id判断一下用户存不存在
        confirm.setEmployeeConfirm(1);
        confirmMapper.updateById(confirm);
    }
}
